package com.wanshi.member.controller;

import com.wanshi.member.base.Result;
import com.wanshi.member.entity.Staff;
import com.wanshi.member.req.PasswordREQ;
import com.wanshi.member.service.IStaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class AuthController {

    @Autowired
    private IStaffService staffService;


    /**
     * 校验原密码是否正确， localhost:6666/user/pwd
     * @param req
     * @return
     */
    @PostMapping("/pwd")
    public Result checkPwd(@RequestBody PasswordREQ req) {
        return staffService.checkPassword(req);
    }

    /**
     * 提交修改密码  localhost:6666/user/pwd  请求方式PUT
     * @param req
     * @return
     */
    @PutMapping("/pwd")
    public Result updatePwd(@RequestBody PasswordREQ req) {
        return staffService.updatePassword(req);
    }



    @PostMapping("/login")
    public Result login(@RequestBody Staff staff) {
        //int x = 5/0;

        int y = 2;

        if(y == 2){
           // throw new MyException("故意抛出的异常");
        }


        return staffService.login(staff.getUsername(), staff.getPassword());
    }

    /**
     * /user/info?token=xxxx
     * 通过 token 获取用户信息
     * @param token
     * @return
     */
    @GetMapping("/info")
    public Result getUserInfo(@RequestParam String token) {
        return staffService.getUserInfo(token);
    }



}
